#pragma once

#include <iostream>
#include <string>
#include <unistd.h>
#include <vector>
#include <functional>

class Channel{
public:
    Channel(int wfd, pid_t who) : _wfd(wfd), _who(who) {
        _name = "Channel-" + std::to_string(wfd) + "-" + std::to_string(who);
    }

    std::string Name()
    {
        return _name;
    }
    void Send(int cmd) 
    {
        ::write(_wfd, &cmd, sizeof(cmd));
    }
    void Close() {
        ::close(_wfd);
    }
    pid_t Id()
    {
        return _who;
    }
    int wFD()
    {
        return _wfd;
    }
    ~Channel() {
        
    }

private:
    int _wfd;           // 写端文件描述符
    std::string _name;  // 通道名称
    pid_t _who;         // 进程ID
};